package com.hxh.tess4j;

import com.alibaba.fastjson.JSONObject;
import com.hxh.tess4j.dto.Result;
import com.hxh.tess4j.util.OkhttpUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.concurrent.Executors;

/**
 * @author huangxunhui
 * Date: Created in 2019-04-15 23:16
 * Utils: Intellij Idea
 * Description:
 */
@Slf4j
public class SendSmsCode {

    private static final String URL = "https://appnew.loserbank.com/newweb/newloginreg/getYzmNew";

    private static final String CODE_IS_VALID = "图片验证码已失效，请刷新";

    private static final String CODE_IS_ERROR = "图片验证码输入错误";

    private static volatile String code = DiscernCode.code();

    private static void send() {
        HashMap<String,String> map = new HashMap<>(3);
        map.put("tpyzm",code);
        map.put("phone","183191"+ OkhttpUtil.getNum());
        String ret = OkhttpUtil.get(URL, map);
        log.info("返回值:{},验证码是:{}",ret,code.trim());
        Result result = JSONObject.parseObject(ret, Result.class);
        if(CODE_IS_VALID.equals(result.getMsg()) ||  CODE_IS_ERROR.equals(result.getMsg())){
            code = DiscernCode.code();
        }
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            send();
        }
    }
}
